<template>
  <div>
    <div style="height:50px;"></div>
    <!--列表-->
    <el-form :model="addForm" label-width="80px" :rules="addFormRules" ref="addForm">
      <el-form-item label="用户id" prop="uids">
        <el-input v-model="addForm.uids" auto-complete="off" placeholder="多个以英文逗号隔开，不填则为群发"></el-input>
      </el-form-item>
      <el-form-item label="标题" prop="title">
        <el-input v-model="addForm.title" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="内容" prop="content">
        <el-input v-model="addForm.content" auto-complete="off"></el-input>
      </el-form-item>
      <el-form-item label="特殊资源" prop="type">
        <el-radio-group v-model="addForm.type">
          <el-radio label="1">活动</el-radio>
          <el-radio label="2">通知</el-radio>
        </el-radio-group>
      </el-form-item>
      <el-form-item label="跳转链接">
        <el-input v-model="addForm.jump_to" auto-complete="off" width="80px"></el-input>
      </el-form-item>
    </el-form>
    <div slot="footer" class="dialog-footer" style="text-align:right;">
      <el-button type="primary" @click.native="addSubmit" :loading="addLoading">发布</el-button>
    </div>
  </div>  
</template>

<!-- <script type="text/ecmascript-6"> -->
<script>
  import { apiTree } from '../../apiTree'

  export default {
    data() {
      return {
        addFormRules: {
          title: [
            {required: true, message: '请输入标题', trigger: 'blur'}
          ],
          content: [
            {required: true, message: '请输入内容', trigger: 'blur'}
          ]
        },
        // 新增界面数据
        addForm: {
          type: '1'
        },
        addLoading: false
      }
    },
    methods: {
      // 新增
      addSubmit: function () {
        this.$refs.addForm.validate((valid) => {
          if (valid) {
            this.$confirm('确认提交吗？', '提示', {}).then(() => {
              this.addLoading = true
              apiTree('notice/index', 'advert/notice', this.addForm).then((res) => {
                if (res.s === 1) {
                  this.$message({
                    message: '命令执行完毕',
                    type: 'success'
                  })
                } else {
                  this.$alert('出问题了')
                }
              })
              this.addLoading = false
            })
          }
        })
      }
    }
  }

</script>

